<template>
	<view class="home-container">
		<loading v-if="filmTypes.length==0"></loading>
		<!-- 电影类型 -->
		<view class="film-type" v-for="(item,index) in filmTypes" :key='index'>
			<!-- 标题 -->
			<view class="film-title">
				<text class="title">{{item.title}}</text>
				<text class="more" @click="goToList(item)">更多 ></text>
			</view>
			<!-- 电影列表项 -->
			<scroll-view scroll-x="true" enable-flex='true' class="film-list">
				<!-- 电影每一项 -->
				<film-item v-for="(item1,index1) in item.list" :key='index1' :film='item1' class="film-item"></film-item>	
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				filmTypes:[],
				isloading:false
			};
		},
		methods:{
			// 获取影院热映请求
			async getHotFilm(){
				await uni.request({
					url:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items',
					method:"GET",
					data:{
						start:0,
						count:6,
						
					}
				}).then(res=>{
					// console.log(res[1].data)
					const type={
						title:res[1].data.subject_collection.name,
						list:res[1].data.subject_collection_items,
						id:res[1].data.subject_collection.id
					}
					this.filmTypes.push(type)
					
				}).catch(err=>err)
				
			},
			// 获取近期热门请求
			async getLatestFilm(){
				await uni.request({
					url:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_latest/items',
					method:"GET",
					data:{
						start:0,
						count:6
					}
				}).then(res=>{
					// console.log(res[1].data)
					const type1={
						title:res[1].data.subject_collection.name,
						list:res[1].data.subject_collection_items,
						id:res[1].data.subject_collection.id
					}
					this.filmTypes.push(type1)
					this.isloading=true
				}).catch(err=>err)
				
			},
			// 获取免费电影请求
			async getFreeFilm(){
				await uni.request({
					url:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_free_stream/items',
					method:"GET",
					data:{
						start:0,
						count:6
					}
				}).then(res=>{
					// console.log(res[1].data)
					const type2={
						title:res[1].data.subject_collection.name,
						list:res[1].data.subject_collection_items,
						id:res[1].data.subject_collection.id
					}
					this.filmTypes.push(type2)
				}).catch(err=>err)
			},
			// 跳转更多
			goToList(item){
				uni.navigateTo({
					url:'../../subpkg/filmList/filmList?id='+item.id
				})
			}
		},
		onLoad() {
			this.getHotFilm()
			this.getLatestFilm()
			this.getFreeFilm()
			
		}
	}
</script>

<style lang="scss">
.home-container{
	// 电影类型
	.film-type{
		background-color: #FFFFFF;
		margin-bottom: 20rpx;
		//标题
		.film-title{
			padding: 26rpx 0;
			font-size: 28rpx;
			font-weight: bold;
			.title{
				padding-left: 26rpx;
				border-left: 8rpx solid #42bd56;
			}
			.more{
				float: right;
				margin-right: 30rpx;
				color: #42bd56;
			}
		}
		//电影列表项
		.film-list{
			width: 100%;
			height: 370rpx;
			display: flex;
			//电影每一项
			.film-item{
				width: 200rpx;
				padding: 0 12rpx;
				display: inline-block;
			}
		}
	}
}
</style>
